home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 4
/
The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO
/
clang
/
3d_lib.zip
/
TEST.C
< prev
next >
Wrap
Text File
|
1993-05-09
|
8KB
|
288 lines
#include <3d.h>
#include <alloc.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
#include <graphics.h>
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
void setup();
int huge alwayszero(void);
void _Cdecl vga256_driver(void);
int huge alwayszero(void)
{
return 0;
}
void setup()
{
int gdriver,gmode;
gdriver = installuserdriver("vga256", alwayszero);
registerbgidriver(vga256_driver);
initgraph(&gdriver,&gmode,"");
}
void main()
{
FACE *f,*g,*h,*i,*j,*k; /* Faces of cube */
FACE *t1,*t2,*t3,*t4; /* Faces of tetrahedron */
FACE *o1,*o2,*o3,*o4,*o5,*o6,*o7,*o8; /* Faces of octahedron */
VECTOR n,s;
MATRIX xm,ym,xr,yr,om,or,id; /* Transformation matrices */
OBJECT *o; /* Cube */
OBJECT *p; /* Tetrahedron */
OBJECT *q; /* Octahedron */
int apage,vpage,tpage,frame;
/* Initialize matrices and data structures */
identity (xm);
identity (ym);
identity (xr);
identity (yr);
identity (id);
identity (om);
identity (or);
f = (FACE *)malloc(sizeof(FACE));
g = (FACE *)malloc(sizeof(FACE));
h = (FACE *)malloc(sizeof(FACE));
i = (FACE *)malloc(sizeof(FACE));
j = (FACE *)malloc(sizeof(FACE));
k = (FACE *)malloc(sizeof(FACE));
t1 = (FACE *)malloc(sizeof(FACE));
t2 = (FACE *)malloc(sizeof(FACE));
t3 = (FACE *)malloc(sizeof(FACE));
t4 = (FACE *)malloc(sizeof(FACE));
o1 = (FACE *)malloc(sizeof(FACE));
o2 = (FACE *)malloc(sizeof(FACE));
o3 = (FACE *)malloc(sizeof(FACE));
o4 = (FACE *)malloc(sizeof(FACE));
o5 = (FACE *)malloc(sizeof(FACE));
o6 = (FACE *)malloc(sizeof(FACE));
o7 = (FACE *)malloc(sizeof(FACE));
o8 = (FACE *)malloc(sizeof(FACE));
o = (OBJECT *)malloc(sizeof(OBJECT));
new_obj (o);
p = (OBJECT *)malloc(sizeof(OBJECT));
new_obj (p);
q = (OBJECT *)malloc(sizeof(OBJECT));
new_obj (q);
/* Define cube */
new_face (f);
add_corner ( 0.0, 0.0, 0.0,f);
add_corner ( 25.0, 0.0, 0.0,f);
add_corner ( 25.0, 25.0, 0.0,f);
add_corner ( 0.0, 25.0, 0.0,f);
add_face (o,f);
new_face (g);
add_corner ( 0.0, 0.0, 0.0,g);
add_corner ( 0.0, 25.0, 0.0,g);
add_corner ( 0.0, 25.0, 25.0,g);
add_corner ( 0.0, 0.0, 25.0,g);
add_face (o,g);
new_face (h);
add_corner ( 0.0, 0.0, 0.0,h);
add_corner ( 0.0, 0.0, 25.0,h);
add_corner ( 25.0, 0.0, 25.0,h);
add_corner ( 25.0, 0.0, 0.0,h);
add_face (o,h);
new_face (i);
add_corner ( 0.0, 0.0, 25.0,i);
add_corner ( 0.0, 25.0, 25.0,i);
add_corner ( 25.0, 25.0, 25.0,i);
add_corner ( 25.0, 0.0, 25.0,i);
add_face (o,i);
new_face (j);
add_corner ( 0.0, 25.0, 0.0,j);
add_corner ( 25.0, 25.0, 0.0,j);
add_corner ( 25.0, 25.0, 25.0,j);
add_corner ( 0.0, 25.0, 25.0,j);
add_face (o,j);
new_face (k);
add_corner ( 25.0, 0.0, 0.0,k);
add_corner ( 25.0, 0.0, 25.0,k);
add_corner ( 25.0, 25.0, 25.0,k);
add_corner ( 25.0, 25.0, 0.0,k);
add_face (o,k);
/* Define tetrahedron */
new_face (t1);
add_corner ( 0.00, 0.00, 0.00,t1);
add_corner ( 100.00, 0.00, 0.00,t1);
add_corner ( 50.00, 81.65, 28.87,t1);
add_face (p,t1);
new_face (t2);
add_corner ( 0.00, 0.00, 0.00,t2);
add_corner ( 50.00, 0.00, 86.60,t2);
add_corner ( 100.00, 0.00, 0.00,t2);
add_face (p,t2);
new_face (t3);
add_corner ( 0.00, 0.00, 0.00,t3);
add_corner ( 50.00, 81.65, 28.87,t3);
add_corner ( 50.00, 0.00, 86.60,t3);
add_face (p,t3);
new_face (t4);
add_corner ( 100.00, 0.00, 0.00,t4);
add_corner ( 50.00, 0.00, 86.60,t4);
add_corner ( 50.00, 81.65, 28.87,t4);
add_face (p,t4);
/* Define octahedron */
new_face (o1);
add_corner ( 0.00, 70.71, 0.00,o1);
add_corner ( 50.00, 0.00, 50.00,o1);
add_corner ( 100.00, 70.71, 0.00,o1);
add_face (q,o1);
new_face (o2);
add_corner ( 100.00, 70.71, 0.00,o2);
add_corner ( 50.00, 0.00, 50.00,o2);
add_corner ( 100.00, 70.71, 100.00,o2);
add_face (q,o2);
new_face (o3);
add_corner ( 100.00, 70.71, 100.00,o3);
add_corner ( 50.00, 0.00, 50.00,o3);
add_corner ( 0.00, 70.71, 100.00,o3);
add_face (q,o3);
new_face (o4);
add_corner ( 0.00, 70.71, 100.00,o4);
add_corner ( 50.00, 0.00, 50.00,o4);
add_corner ( 0.00, 70.71, 0.00,o4);
add_face (q,o4);
new_face (o5);
add_corner ( 0.00, 70.71, 0.00,o5);
add_corner ( 50.00, 141.40, 50.00,o5);
add_corner ( 0.00, 70.71, 100.00,o5);
add_face (q,o5);
new_face (o6);
add_corner ( 0.00, 70.71, 100.00,o6);
add_corner ( 50.00, 141.40, 50.00,o6);
add_corner ( 100.00, 70.71, 100.00,o6);
add_face (q,o6);
new_face (o7);
add_corner ( 100.00, 70.71, 100.00,o7);
add_corner ( 50.00, 141.40, 50.00,o7);
add_corner ( 100.00, 70.71, 0.00,o7);
add_face (q,o7);
new_face (o8);
add_corner ( 100.00, 70.71, 0.00,o8);
add_corner ( 50.00, 141.40, 50.00,o8);
add_corner ( 0.00, 70.71, 0.00,o8);
add_face (q,o8);
/* The light source in the z direction (from the eye) */
s[0] = 0.25;
s[1] = 0.0;
s[2] = 1.0;
/* Center figures in space and orient them */
/* The following series of function calls illustrates the concatenation
of 3D transforms. Each of three matrices xm, ym, and om is the
concatenation of four transforms; first, center the object on the
origin, second, rotate the object about the y axis, third, rotate the
object about the x axis, and fourth, translate the object to its final
position. All four transforms are concatenated in each matrix, then
the object is transformed. Thus, each vertex in the object is mul-
tiplied by the transformation matrix only once. */
trans (-10,-10,-10,xm);
trans (-10,-10,-10,ym);
trans (-10,-10,-10,om);
yrot (M_PI/4,xm);
yrot (M_PI/3,ym);
yrot (M_PI/4,om);
xrot (M_PI/4,xm);
xrot (M_PI/3,ym);
xrot (M_PI/4,om);
/* Position figures in space */
trans (100,100,100,xm);
trans (200,50,100,ym);
trans (200,150,100,om);
xform (*o,xm);
xform (*p,ym);
xform (*q,om);
/* Set up rotation matrices */
/* These matrices are created to perform an incremental rotation of each
object. First, the object is translated to the origin, second, the
object is rotated, and third, the object is translated back to its
original postion. */
trans (-100,-100,-100,xr);
yrot (M_PI/45,xr);
trans (100,100,100,xr);
trans (-200,-50,-100,yr);
xrot (M_PI/45,yr);
trans (200,100,100,yr);
trans (-200,-200,-100,or);
xrot (M_PI/45,or);
yrot (M_PI/45,or);
trans (200,150,100,or);
apage = 0;
vpage = 1;
setup();
for (frame = 1; frame <= 45; frame++)
{
setvisualpage(vpage);
setactivepage(apage);
tpage = apage;
apage = vpage;
vpage = tpage;
cleardevice();
xform (*o,xr);
xform (*p,yr);
xform (*q,or);
disp_object (s,1,o,id);
disp_object (s,4,p,id);
disp_object (s,2,q,id);
}
closegraph();
}